#!/bin/bash
SERVICES="rpc nfsd ntpd nginx sshd avahidaemon samba"

# run & log functions
. /etc/rc.d/rc.runlog

queue(){
  atq | grep -Pom1 '^\d+'
}

# delayed execution
sleep ${1:-1}

JOB=$(queue)
if [[ -n $JOB ]]; then
  atrm $JOB 2>/dev/null
  log "execute queued job $JOB"
else
  exit 0
fi

for cmd in $SERVICES; do
  /etc/rc.d/rc.$cmd update &>/dev/null
done
exit 0
